package com.project.market.service.impl;

import com.project.market.db.domain.*;
import com.project.market.db.mapper.MarketGoodsMapper;
import com.project.market.db.mapper.MarketGoodsProductMapper;
import com.project.market.db.mapper.MarketOrderMapper;
import com.project.market.db.mapper.MarketUserMapper;
import com.project.market.service.AdminDashBoardService;
import com.project.market.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class AdminDashBoardServiceImpl implements AdminDashBoardService {
    @Override
    public Integer[] getTotal(String[] str) {
        Integer[] ints = new Integer[str.length];

        MarketAdmin marketAdmin=null;
        //   "goodsTotal","userTotal",
        //   "productTotal","orderTotal"
        SqlSession session = MybatisUtil.getSession();
        MarketGoodsMapper marketGoods = session.getMapper(MarketGoodsMapper.class);
        MarketUserMapper marketUser = session.getMapper(MarketUserMapper.class);
        MarketGoodsProductMapper marketGoodsProduct = session.getMapper(MarketGoodsProductMapper.class);
        MarketOrderMapper marketOrder = session.getMapper(MarketOrderMapper.class);

        ints[0] = Math.toIntExact(marketGoods.countByExample(new MarketGoodsExample()));

        ints[1] = Math.toIntExact(marketUser.countByExample(new MarketUserExample()));

        ints[2] = Math.toIntExact(marketGoodsProduct.countByExample(new MarketGoodsProductExample()));

        ints[3] = Math.toIntExact(marketOrder.countByExample(new MarketOrderExample()));

        session.commit();
        session.close();

        return ints;
    }
}
